package com.example.h.weixinui3;

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * A simple {@link Fragment} subclass.

 */
public class OneFragment extends Fragment {

    public OneFragment() {
        // Required empty public constructor
    }


    private ListView userListView;
    private SimpleAdapter adapter;
    private List<Map<String,Object>> data;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view= inflater.inflate(R.layout.fragment_one, container, false);
        userListView=(ListView)view.findViewById(R.id.listView_1);
        //绑定数据
        String[] from={"userImage","userName","userInfo"};
        int[] to={R.id.userImage,R.id.userName,R.id.userInfo};
        getData();
        adapter=new SimpleAdapter(this.getActivity(),data,R.layout.layout_userlist,from,to);
        userListView.setAdapter(adapter);
        return view;
    }

    private void getData(){
        data=new ArrayList<Map<String,Object>>();
        //每一项的数据
        Map<String,Object> map=new HashMap<String,Object>();
        map.put("userImage",R.drawable.afn);
        map.put("userName","张三");
        map.put("userInfo","Android兴趣班班长");
        data.add(map);

        map=new HashMap<String,Object>();
        map.put("userImage",R.drawable.a_i);
        map.put("userName","李四");
        map.put("userInfo","Android兴趣班学习委员");
        data.add(map);

        map=new HashMap<String,Object>();
        map.put("userImage",R.drawable.af7);
        map.put("userName","小强");
        map.put("userInfo","Android兴趣班组织委员");
        data.add(map);

        map=new HashMap<String,Object>();
        map.put("userImage",R.drawable.ak0);
        map.put("userName","欧阳锋");
        map.put("userInfo","Android兴趣班打酱油人员");
        data.add(map);
    }

}
